'use strict';

angular.module('app').controller('reportController', [ '$rootScope', '$scope', '$http', '$state','toaster','$modal',
    function($rootScope, $scope, $http, $state,toaster,$modal) {
        $scope.title = '人员报表';
        $scope.loading = false;
        sex();
        age();
        nation();
        province();
        //性别统计
        function sex() {
            $scope.loading = true;
            var myChart = echarts.init(document.getElementById('sexReport'));
           // 异步加载数据
            $.get('/dac/report/person/sex').done(function (result) {
                $scope.loading = false;
                function getsex(){
                    var series = [];
                    for(var i = 0; i < result.data.length; i++){
                        var item = {
                            value: result.data[i].value,
                            name:result.data[i].name
                        }
                        series.push(item );
                    };
                    return series;
                }
                myChart.setOption({
                    title: {
                        text: '性别统计',
                        left:'center',
                        fontWeight:'normal'
                    },
                    tooltip : {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    color:['#6490f2', '#444'],
                    series:[{
                        type: 'pie',
                        radius : '55%',
                        center: ['50%','60%'],
                        min:'1',
                        data:getsex(),
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            },
                            normal:{
                                label:{
                                    show: true,
                                    formatter: '{b} : {c} ({d}%)'
                                },
                                labelLine :{show:true}
                            }
                        }
                    }]

                });

            });
        }
        //年龄统计
        function age() {
            $scope.loading = true;
            var myChart = echarts.init(document.getElementById('ageReport'));
            $.get('/dac/report/person/age').done(function (result) {
                $scope.loading = false;
                function getage() {
                    return result.data;
                }
                myChart.setOption({
                    title: {
                        text: '年龄统计',
                        left: 'center',
                        fontWeight:'normal'
                    },
                    tooltip: {},
                    // legend: {
                    //     data:['销量']
                    // },
                    xAxis: {
                        type: 'value',
                        boundaryGap: [0, 0.01],
                        min:'0'
                    },
                    yAxis: {
                        type: 'category',
                        data:['18以下','18-30岁','31-60岁','60岁以上']
                    },
                    series:[{
                        // name: '2011年',
                        type: 'bar',
                        barWidth:'20px',
                        itemStyle: {
                            normal:{
                                color:'#6490f2'
                            }
                        },
                        label: {
                            normal: {
                                show: true,
                                position: 'right',
                                color:'#555'
                            }
                        },
                        data:getage()
                    }]
                })

            })
        }
        //民族统计
        function nation() {
          $scope.loading = true;
          var myChart = echarts.init(document.getElementById('nationReport'));
          $.get('/dac/report/person/nation').done(function (result) {
            $scope.loading = false;
            function getnation() {
                var series = [];
                for (var i = 0; i < result.data.length; i++) {
                    var item = {
                        value: result.data[i].value,
                        name: result.data[i].name
                    }
                    series.push(item);
                }
                return series;
            }
              myChart.setOption({
                  title : {
                      text: '民族统计',
                      left:'center',
                      fontWeight:'normal'
                  },
                  tooltip : {
                      trigger: 'item',
                      formatter: "{a} <br/>{b} : {c} ({d}%)"
                  },
                  color:['#7266b', '#6490f2','#23b7e5','#27c24c','#f05050','#3a3f51','#fad733'],
                  series : [{
                              type: 'pie',
                              radius : '55%',
                              center: ['50%', '60%'],
                              data:getnation(),
                              itemStyle: {
                                  emphasis: {
                                      shadowBlur: 10,
                                      shadowOffsetX: 0,
                                      shadowColor: 'rgba(0, 0, 0, 0.5)'
                                  },
                                  normal:{
                                      label:{
                                          show: true,
                                          formatter: '{b} : {c} ({d}%)'
                                      },
                                      labelLine :{show:true}
                                  }
                              }
                         }]
              })
          })

        }
        //省市统计
        function province() {
            $scope.loading = true;
            var myChart = echarts.init(document.getElementById('provinceReport'));
            $.get('/dac/report/person/province').done(function (result) {
                $scope.loading = false;
                function getprovince() {
                    var series= [];
                    for(var i=0 ;i<result.data.length;i++){
                        var item = {
                            value:result.data[i].value,
                            name:result.data[i].name
                        }
                        series.push(item);
                    }
                    return series;
                }
                myChart.setOption({
                    title: {
                        text: '省份统计',
                        subtext: '',
                        left: 'center',
                    },
                    tooltip: {
                        trigger: 'item'
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                       // data:['人数统计']
                    },
                    visualMap: {
                        min: 0,
                        max: 100,
                        left: 'left',
                        top: 'bottom',
                        text: ['高','低'],           // 文本，默认为数值文本
                        calculable: true
                    },
                    // toolbox: {
                    //     show: true,
                    //     orient: 'vertical',
                    //     left: 'right',
                    //     top: 'center',
                    //     feature: {
                    //         dataView: {readOnly: false},
                    //         restore: {},
                    //         saveAsImage: {}
                    //     }
                    // },
                    series: [{
                            name: '人数统计',
                            type: 'map',
                            mapType: 'china',
                            roam: false,
                            label: {
                                normal: {
                                    show: true
                                },
                                emphasis: {
                                    show: true
                                }
                            },
                            data:getprovince()
                        }]
                })
            })


        }
    }
]);

        











